#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
using namespace std;

#include<string>
#include"string.h"

void test_string1()
{
	lkm::string str1("hello world");
	cout << str1.c_str() << endl;

	lkm::string str2;
	cout << str2.c_str() << endl;

	/*for (size_t i = 0; i < str1.size(); i++)
	{
		str1[i]++;
	}
	cout << endl;*/

	for (size_t i = 0; i < str1.size(); i++)
	{
		cout << str1[i] << " ";
	}
	cout << endl;

	const lkm::string str3("hello world");
	//str3[0] = 'a';

	lkm::string::const_iterator cit = str3.begin();
	while (cit != str3.end())
	{
		cout << *cit << " ";
		cit++;
	}
	cout << endl;

	lkm::string::iterator it = str1.begin();
	while (it != str1.end())
	{
		cout << *it << " ";
		it++;
	}
	cout << endl;

	for (auto ch : str3)
	{
		cout << ch << " ";
	}
	cout << endl;
}

void test_string2()
{
	lkm::string s1("hello world");
	s1.push_back('*');
	s1.push_back('%');
	cout << s1.c_str() << endl;

	s1.append("hello bit");
	cout << s1.c_str() << endl;

	lkm::string s2("hello");
	s2 += 'Q';
	s2 += ' ';
	s2 += "abcd";
	cout << s2.c_str() << endl;

}

void test_string3()
{
	lkm::string s1 = "hello world";
	lkm::string s2 = "hello world";
	s1.insert(6, 2, '*');
	cout << s1.c_str() << endl;
	s2.insert(0, 2, '#');
	cout << s2.c_str() << endl;

	s2.insert(5, "$$$$");
	cout << s2.c_str() << endl;


}

void test_string4()
{
	lkm::string s1("helloworld");
	cout << s1.c_str() << endl;

	s1.erase(5, 3);
	cout << s1.c_str() << endl;

	s1.erase(5, 30);
	cout << s1.c_str() << endl;

	s1.erase(2);
	cout << s1.c_str() << endl;
}

void test_string5()
{
	// 2118
	lkm::string url = "ftp://www.baidu.com/?tn=65081411_1_oem_dg";

	size_t pos1 = url.find("://");
	if (pos1 != lkm::string::npos)
	{
		lkm::string protocol = url.substr(0, pos1);
		cout << protocol.c_str() << endl;
	}

	size_t pos2 = url.find('/', pos1 + 3);
	if (pos2 != lkm::string::npos)
	{
		lkm::string domain = url.substr(pos1 + 3, pos2 - (pos1 + 3));
		lkm::string uri = url.substr(pos2 + 1);

		cout << domain.c_str() << endl;
		cout << uri.c_str() << endl;
	}
}

void test_string6()
{
	lkm ::string s("hello world");
	s.resize(8);
	cout << s.c_str() << endl;
	

	s.resize(13, 'x');
	cout << s.c_str() << endl;
	

	s.resize(20, 'y');
	cout << s.c_str() << endl;
	
	lkm::string ss("hello world");
	ss += '\0';
	ss += "!!!!!!!!!!";
	cout << ss.c_str() << endl;
	cout << ss << endl;

	lkm::string copy(ss);
	cout << ss << endl;
	cout << copy << endl;

	ss += "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
	cout << ss << endl;
}


void test_string7()
{
	lkm::string s;
	cin >> s;
	cout << s << endl;

	cin >> s;
	cout << s << endl;

	//char buff[128];
	//for (size_t i = 0; i < 5; i++)
	//{
	//	cin >> buff[i];
	//}

	//for (size_t i = 0; i < 5; i++)
	//{
	//	cout << buff[i] << endl;
	//}
}

void test_string8()
{
	//string s1("bb");
	//string s2("aaa");
	//cout << (s1 < s2) << endl;

	lkm::string s1("hello");
	lkm::string s2("hello");
	cout << (s1 < s2) << endl;
	cout << (s1 > s2) << endl;
	cout << (s1 == s2) << endl << endl;


	lkm::string s3("hello");
	lkm::string s4("helloxxx");
	cout << (s3 < s4) << endl;
	cout << (s3 > s4) << endl;
	cout << (s3 == s4) << endl << endl;


	lkm::string s5("helloxxx");
	lkm::string s6("hello");
	cout << (s5 < s6) << endl;
	cout << (s5 > s6) << endl;
	cout << (s5 == s6) << endl << endl;
}

void test_string9()
{
	lkm::string s1("hello");
	lkm::string s2(s1);

	cout << s1 << endl;
	cout << s2 << endl;

	lkm::string s3("xxxxxxxxxxxxx");
	s1 = s3;

	cout << s1 << endl;
	cout << s3 << endl;

	s3 += '\0';
	s3 += "yyyyyyyyyyyyy";

	lkm::string s4(s3);
	cout << s4 << endl;
}

int main()
{
	test_string9();
	return 0;
}


